//
//  CTSubjectCell.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/5.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTSubjectCell.h"
#import "CTDebugManager.h"
#import "CTRequestUtil.h"
#import "CTHeader.h"
#import "CTAppLanguage.h"
#import "CTHomePageItems.h"
#import "CTDeviceFunction.h"

@interface CTSubjectCell ()
{
    UIImageView * picImageView;
    UILabel * subjectDescribeLabel;
    
    UILabel * partiPersonCountLabel;
    UILabel * personCountDescriLabel;
    
    UIButton * stickerDetailBtn;
    UIButton * shareBtn;
    
    UIView * bottomLine;
    
}

@end

@implementation CTSubjectCell
@synthesize delegate;

- (void)dealloc
{
    [picImageView removeFromSuperview];
    picImageView = nil;
    
    [subjectDescribeLabel removeFromSuperview];
    subjectDescribeLabel = nil;
    
    [partiPersonCountLabel removeFromSuperview];
    partiPersonCountLabel = nil;
    
    [personCountDescriLabel removeFromSuperview];
    personCountDescriLabel = nil;
    
    [stickerDetailBtn removeFromSuperview];
    stickerDetailBtn = nil;
    
    [shareBtn removeFromSuperview];
    shareBtn = nil;
    
    [bottomLine removeFromSuperview];
    bottomLine = nil;
    
    delegate = nil;
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTSubjectCell Is Removed!!!"];
}



- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        
        self.backgroundColor = CT_HEADER_WHITE_COLOR;
        [self creatSubViews];
    }
    
    return self;
}

-(void)creatSubViews
{
    picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_WIDTH/2.678)];
    picImageView.backgroundColor = CT_HEADER_WHITE_COLOR;
    picImageView.image = [UIImage imageNamed:@"faxianredianshuiyin"];
    [self addSubview:picImageView];
//    DeviceTypeAdaptation deviceType  = [CTDeviceFunction deviceTypeForResolutionAdaptation];
//    if (deviceType == iPhone6)
//    {
//        picImageView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 140);
//    }
//    else if (deviceType == iPhone6_Plus)
//    {
//        picImageView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 202);
//    }
//    else
//    {
//        picImageView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 120);
//    }
    subjectDescribeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    subjectDescribeLabel.font = [UIFont systemFontOfSize:13];
//    [subjectDescribeLabel setNumberOfLines:0];
//    subjectDescribeLabel.lineBreakMode = NSLineBreakByWordWrapping;
    subjectDescribeLabel.textColor = [UIColor colorWithRed:164/255.0 green:164/255.0 blue:164/255.0 alpha:1.0];
    subjectDescribeLabel.frame = CGRectMake(10,picImageView.bounds.size.height+15,260,15);
    [self addSubview:subjectDescribeLabel];
    
    
    partiPersonCountLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [partiPersonCountLabel setNumberOfLines:0];
    partiPersonCountLabel.lineBreakMode = NSLineBreakByWordWrapping;
    partiPersonCountLabel.font = [UIFont systemFontOfSize:15];
    partiPersonCountLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
    [self addSubview:partiPersonCountLabel];
    personCountDescriLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    personCountDescriLabel.text = [CTAppLanguage localizedStringForKey:@"CTSubjectCell_PartiPersonCountDescri" withValue:nil withTable:@"Language"];
    personCountDescriLabel.font = [UIFont systemFontOfSize:15];
    personCountDescriLabel.textColor = [UIColor colorWithRed:164/255.0 green:164/255.0 blue:164/255.0 alpha:1.0];
    [self addSubview:personCountDescriLabel];
    
    
    stickerDetailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [stickerDetailBtn addTarget:self action:@selector(checkStickerDetailsBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [stickerDetailBtn setBackgroundImage:[UIImage imageNamed:@"zhuantianniu_chakan_bg"] forState:UIControlStateNormal];
    [self addSubview:stickerDetailBtn];
    UILabel * stickerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 55, 15)];
    stickerLabel.font = [UIFont systemFontOfSize:15.0];
    stickerLabel.textAlignment = NSTextAlignmentCenter;
    stickerLabel.textColor = CT_HEADER_GREEN_COLOR;
    stickerLabel.text = [CTAppLanguage localizedStringForKey:@"CTSubjectCell_Subject" withValue:nil withTable:@"Language"];
    [stickerDetailBtn addSubview:stickerLabel];
    
    shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareBtn addTarget:self action:@selector(shareBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [shareBtn setBackgroundImage:[UIImage imageNamed:@"zhuantianniu_share_bg"] forState:UIControlStateNormal];
    [self addSubview:shareBtn];
    UILabel * shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 55, 15)];
    shareLabel.font = [UIFont systemFontOfSize:15.0];
    shareLabel.textAlignment = NSTextAlignmentCenter;
    shareLabel.textColor = CT_HEADER_ORANGE_COLOR;
    shareLabel.text = [CTAppLanguage localizedStringForKey:@"CTSubjectCell_Share" withValue:nil withTable:@"Language"];
    [shareBtn addSubview:shareLabel];
    
    
    
    bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 0.5)];
    bottomLine.backgroundColor = [UIColor colorWithRed:201/255.0 green:201/255.0 blue:201/255.0 alpha:1.0];
    [self addSubview:bottomLine];
}


#pragma mark - action -

-(void)checkStickerDetailsBtnAction:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(checkStickerDetailsAction:)]) {
        [self.delegate checkStickerDetailsAction:self];
    }
}

-(void)shareBtnAction:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(shareAction:)]) {
        [self.delegate shareAction:self];
    }
}


#pragma mark - setter -

-(void)setSubjectItem:(CTSubjectItem *)item
{

    
    [CTRequestUtil requestImgWithUrl:item.hotspot.thumb withCompletionSuccessHandler:^(UIImage *img) {
        picImageView.image = img;
    } withFailedHandler:^(NSError *error) {
        
    }];
    
    
    
    
    CGSize sub_labelSize;
    sub_labelSize = [item.hotspot.describe sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(CT_HEADER_SCREEN_WIDTH-20, 200) lineBreakMode:NSLineBreakByWordWrapping];
//    subjectDescribeLabel.frame = CGRectMake(10,picImageView.bounds.size.height+15,sub_labelSize.width,sub_labelSize.height);
    subjectDescribeLabel.text = item.hotspot.describe;
    
    
    stickerDetailBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-135,picImageView.bounds.size.height+15+subjectDescribeLabel.bounds.size.height+12, 55, 25);
    shareBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-65,picImageView.bounds.size.height+15+subjectDescribeLabel.bounds.size.height+12, 55, 25);
    
    
    
    CGSize labelSize;
    labelSize = [item.temperature sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(150, 15) lineBreakMode:NSLineBreakByWordWrapping];
    partiPersonCountLabel.frame = CGRectMake(10.5, subjectDescribeLabel.frame.origin.y+subjectDescribeLabel.bounds.size.height+16, labelSize.width, labelSize.height);
    partiPersonCountLabel.text = item.temperature;
    
    personCountDescriLabel.frame = CGRectMake(10.5+partiPersonCountLabel.bounds.size.width,partiPersonCountLabel.frame.origin.y+2, 100, 15);
    
    bottomLine.frame = CGRectMake(0, stickerDetailBtn.frame.origin.y + 25+19.5, CT_HEADER_SCREEN_WIDTH, 0.5);
    
    
    
    self.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, stickerDetailBtn.frame.origin.y + 25 +20);
    
    
}






@end
